﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Issues.GangLeaderNeedsRecruitsIssueBehavior
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Issues
{
  public class GangLeaderNeedsRecruitsIssueBehavior : CampaignBehaviorBase
  {
    private const IssueBase.IssueFrequency GangLeaderNeedsRecruitsIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

    public override void RegisterEvents()
    {
      CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener((object) this, new Action<Hero>(this.OnCheckForIssue));
    }

    public override void SyncData(IDataStore dataStore)
    {
    }

    private static bool ConditionsHold(Hero issueGiver)
    {
      return issueGiver.CurrentSettlement != null && issueGiver.IsGangLeader;
    }

    public void OnCheckForIssue(Hero hero)
    {
      if (GangLeaderNeedsRecruitsIssueBehavior.ConditionsHold(hero))
        Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(GangLeaderNeedsRecruitsIssueBehavior.OnSelected), typeof (GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssue), IssueBase.IssueFrequency.VeryCommon));
      else
        Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof (GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssue), IssueBase.IssueFrequency.VeryCommon));
    }

    private static IssueBase OnSelected(in PotentialIssueData pid, Hero issueOwner)
    {
      return (IssueBase) new GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssue(issueOwner);
    }

    public class GangLeaderNeedsRecruitsIssue : IssueBase
    {
      private const int IssueAndQuestDuration = 30;
      private const int AlternativeSolutionTroopTierRequirement = 2;
      private const int AlternativeSolutionRelationBonus = 5;
      private const int AlternativeSolutionNotablePowerBonus = 10;
      private const int AlternativeSolutionPlayerHonorBonus = 30;
      private const int AlternativeSolutionRewardPerRecruit = 100;
      private const int CompanionRequiredSkillLevel = 120;

      internal static void AutoGeneratedStaticCollectObjectsGangLeaderNeedsRecruitsIssue(
        object o,
        List<object> collectedObjects)
      {
        ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
      {
        get => IssueBase.AlternativeSolutionScaleFlag.RequiredTroops;
      }

      private int RequestedRecruitCount => 6 + MathF.Ceiling(10f * this.IssueDifficultyMultiplier);

      public override int AlternativeSolutionBaseNeededMenCount
      {
        get => 11 + MathF.Ceiling(9f * this.IssueDifficultyMultiplier);
      }

      protected override int AlternativeSolutionBaseDurationInDaysInternal
      {
        get => 6 + MathF.Ceiling(7f * this.IssueDifficultyMultiplier);
      }

      protected override int RewardGold => 2000 + this.RequestedRecruitCount * 100;

      public override TextObject IssueBriefByIssueGiver
      {
        get
        {
          return new TextObject("{=YxtiyxSf}Yes... As you no doubt know, this is rough work, and I've lost a lot of good lads recently. I haven't had much luck replacing them. I need men who understand how things work in our business, and that's not always easy to find. I could use bandits and looters. They usually know their stuff. But if I take them in as prisoners, they'll just slip away as soon as I get the chance. I need volunteers...[ib:hip][if:convo_undecided_closed]");
        }
      }

      public override TextObject IssueAcceptByPlayer
      {
        get => new TextObject("{=jGpBZDvC}I see. What do you want from me?");
      }

      public override TextObject IssueQuestSolutionExplanationByIssueGiver
      {
        get
        {
          return new TextObject("{=Qh26ReAv}Look, I know that warriors like you can sometimes recruit bandits to your party. Some of those men might want to take their chances working for me. More comfortable in living in town, where there's always drink and women on hand, then roaming endlessly about the countryside, eh? For each one that signs up with me I'll give you a bounty, more if they have some experience.[if:convo_innocent_smile][ib:hip]");
        }
      }

      public override TextObject IssueQuestSolutionAcceptByPlayer
      {
        get => new TextObject("{=ekLDmgS7}I'll find your recruits.");
      }

      public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
      {
        get
        {
          return new TextObject("{=bKfaMFVK}You can also send me a recruiter: a trustworthy companion who is good at leading men, and also enough of a rogue to win the trust of other rogues...[if:convo_undecided_open][ib:confident]");
        }
      }

      public override TextObject IssueAlternativeSolutionAcceptByPlayer
      {
        get
        {
          return new TextObject("{=kxvnA811}All right, I will send you someone from my party who fits your bill.");
        }
      }

      public override TextObject IssueAlternativeSolutionResponseByIssueGiver
      {
        get
        {
          return new TextObject("{=8sDjwsnW}I'm sure your lieutenant will solve my problem. Thank you for your help.[if:convo_nonchalant][ib:demure2]");
        }
      }

      public override TextObject IssueDiscussAlternativeSolution
      {
        get
        {
          return new TextObject("{=TkvsBd4H}Your companion seems to have a knack with the local never-do-wells. I hear a lot of fine lads have already signed up.[if:convo_relaxed_happy][ib:hip2]");
        }
      }

      public override bool IsThereAlternativeSolution => true;

      public override bool IsThereLordSolution => false;

      protected override TextObject AlternativeSolutionStartLog
      {
        get
        {
          TextObject to = new TextObject("{=wX14wxqF}You asked {COMPANION.LINK} to deliver at least {WANTED_RECRUIT_AMOUNT} looters and bandits to {ISSUE_GIVER.LINK} in {SETTLEMENT}. They should rejoin your party in {RETURN_DAYS} days.");
          to.SetCharacterProperties("ISSUE_GIVER", this.IssueOwner.CharacterObject);
          to.SetCharacterProperties("COMPANION", this.AlternativeSolutionHero.CharacterObject);
          to.SetTextVariable("WANTED_RECRUIT_AMOUNT", this.RequestedRecruitCount);
          to.SetTextVariable("SETTLEMENT", this.IssueOwner.CurrentSettlement.EncyclopediaLinkWithName);
          to.SetTextVariable("RETURN_DAYS", this.GetTotalAlternativeSolutionDurationInDays());
          return to;
        }
      }

      public override TextObject Title => new TextObject("{=rrh7rSLs}Gang Needs Recruits");

      public override TextObject Description
      {
        get
        {
          TextObject to = new TextObject("{=0kYaAb7c}A gang leader needs recruits for {?ISSUE_GIVER.GENDER}her{?}his{\\?} gang.");
          to.SetCharacterProperties("ISSUE_GIVER", this.IssueOwner.CharacterObject);
          return to;
        }
      }

      public GangLeaderNeedsRecruitsIssue(Hero issueOwner)
        : base(issueOwner, CampaignTime.DaysFromNow(30f))
      {
      }

      protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
      {
        return issueEffect == DefaultIssueEffects.IssueOwnerPower ? -0.1f : 0.0f;
      }

      public override (SkillObject, int) GetAlternativeSolutionSkill(Hero hero)
      {
        return (hero.GetSkillValue(DefaultSkills.Leadership) >= hero.GetSkillValue(DefaultSkills.Roguery) ? DefaultSkills.Leadership : DefaultSkills.Roguery, 120);
      }

      public override bool DoTroopsSatisfyAlternativeSolution(
        TroopRoster troopRoster,
        out TextObject explanation)
      {
        explanation = TextObject.Empty;
        return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, this.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2);
      }

      public override bool AlternativeSolutionCondition(out TextObject explanation)
      {
        explanation = TextObject.Empty;
        return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, this.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2);
      }

      public override bool IsTroopTypeNeededByAlternativeSolution(CharacterObject character)
      {
        return character.Tier >= 2;
      }

      protected override void OnGameLoad()
      {
      }

      protected override void HourlyTick()
      {
      }

      protected override QuestBase GenerateIssueQuest(string questId)
      {
        return (QuestBase) new GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest(questId, this.IssueOwner, CampaignTime.DaysFromNow(30f), this.RequestedRecruitCount);
      }

      public override IssueBase.IssueFrequency GetFrequency()
      {
        return IssueBase.IssueFrequency.VeryCommon;
      }

      protected override bool CanPlayerTakeQuestConditions(
        Hero issueGiver,
        out IssueBase.PreconditionFlags flag,
        out Hero relationHero,
        out SkillObject skill)
      {
        flag = IssueBase.PreconditionFlags.None;
        relationHero = (Hero) null;
        skill = (SkillObject) null;
        if ((double) issueGiver.GetRelationWithPlayer() < -10.0)
        {
          flag |= IssueBase.PreconditionFlags.Relation;
          relationHero = issueGiver;
        }
        return flag == IssueBase.PreconditionFlags.None;
      }

      public override bool IssueStayAliveConditions() => true;

      protected override void CompleteIssueWithTimedOutConsequences()
      {
      }

      protected override int CompanionSkillRewardXP
      {
        get => (int) (500.0 + 700.0 * (double) this.IssueDifficultyMultiplier);
      }

      protected override void AlternativeSolutionEndWithSuccessConsequence()
      {
        TraitLevelingHelper.OnIssueSolvedThroughQuest(this.IssueOwner, new Tuple<TraitObject, int>[1]
        {
          new Tuple<TraitObject, int>(DefaultTraits.Honor, 30)
        });
        this.IssueOwner.AddPower(10f);
        this.RelationshipChangeWithIssueOwner = 5;
      }
    }

    public class GangLeaderNeedsRecruitsIssueQuest : QuestBase
    {
      private const int QuestGiverRelationBonusOnSuccess = 5;
      private const int QuestGiverNotablePowerBonusOnSuccess = 10;
      private const int QuestGiverRelationPenaltyOnFail = -5;
      private const int NotablePowerPenaltyOnFail = -10;
      private const int PlayerHonorBonusOnSuccess = 30;
      [SaveableField(1)]
      private int _requestedRecruitCount;
      [SaveableField(5)]
      private int _deliveredRecruitCount;
      [SaveableField(6)]
      private int _rewardGold;
      [SaveableField(9)]
      private bool _playerReachedRequestedAmount;
      [SaveableField(7)]
      private JournalLog _questProgressLogTest;

      internal static void AutoGeneratedStaticCollectObjectsGangLeaderNeedsRecruitsIssueQuest(
        object o,
        List<object> collectedObjects)
      {
        ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        base.AutoGeneratedInstanceCollectObjects(collectedObjects);
        collectedObjects.Add((object) this._questProgressLogTest);
      }

      internal static object AutoGeneratedGetMemberValue_requestedRecruitCount(object o)
      {
        return (object) ((GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest) o)._requestedRecruitCount;
      }

      internal static object AutoGeneratedGetMemberValue_deliveredRecruitCount(object o)
      {
        return (object) ((GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest) o)._deliveredRecruitCount;
      }

      internal static object AutoGeneratedGetMemberValue_rewardGold(object o)
      {
        return (object) ((GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest) o)._rewardGold;
      }

      internal static object AutoGeneratedGetMemberValue_playerReachedRequestedAmount(object o)
      {
        return (object) ((GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest) o)._playerReachedRequestedAmount;
      }

      internal static object AutoGeneratedGetMemberValue_questProgressLogTest(object o)
      {
        return (object) ((GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest) o)._questProgressLogTest;
      }

      public override TextObject Title => new TextObject("{=rrh7rSLs}Gang Needs Recruits");

      public override bool IsRemainingTimeHidden => false;

      private TextObject QuestStartedLogText
      {
        get
        {
          TextObject to = new TextObject("{=PZI9Smv3}{QUEST_GIVER.LINK}, a gang leader in {SETTLEMENT}, told you that {?QUEST_GIVER.GENDER}she{?}he{\\?} needs recruits for {?QUEST_GIVER.GENDER}her{?}his{\\?} gang. {?QUEST_GIVER.GENDER}She{?}He{\\?} asked you to recruit {NEEDED_RECRUIT_AMOUNT} looters or bandits into your party, then transfer them to {?QUEST_GIVER.GENDER}her{?}him{\\?}. You will be paid for the recruits depending on their experience.");
          to.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
          to.SetTextVariable("SETTLEMENT", this.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
          to.SetTextVariable("NEEDED_RECRUIT_AMOUNT", this._requestedRecruitCount);
          return to;
        }
      }

      private TextObject QuestSuccessLog
      {
        get
        {
          TextObject to = new TextObject("{=3ApJ6LaX}You have transferred the recruits to {QUEST_GIVER.LINK} as promised.");
          to.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
          return to;
        }
      }

      private TextObject QuestFailedWithTimeOutLogText
      {
        get
        {
          TextObject to = new TextObject("{=iUmWTmQz}You have failed to deliver enough recruits in time. {QUEST_GIVER.LINK} must be disappointed.");
          to.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
          return to;
        }
      }

      public GangLeaderNeedsRecruitsIssueQuest(
        string questId,
        Hero questGiver,
        CampaignTime duration,
        int requestedRecruitCount)
        : base(questId, questGiver, duration, 0)
      {
        this._requestedRecruitCount = requestedRecruitCount;
        this._deliveredRecruitCount = 0;
        this._rewardGold = 2000;
        this._playerReachedRequestedAmount = false;
        this.SetDialogs();
        this.InitializeQuestOnCreation();
      }

      private void QuestAcceptedConsequences()
      {
        this.StartQuest();
        this.AddTrackedObject((ITrackableCampaignObject) this.QuestGiver.CurrentSettlement);
        this._questProgressLogTest = this.AddDiscreteLog(this.QuestStartedLogText, new TextObject("{=r8rwl9ZS}Delivered Recruits"), this._deliveredRecruitCount, this._requestedRecruitCount);
      }

      protected override void SetDialogs()
      {
        this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start").NpcLine(new TextObject("{=0QuAZ8YO}I'll be waiting. Good luck.[if:convo_relaxed_happy][ib:confident]")).Condition((ConversationSentence.OnConditionDelegate) (() => Hero.OneToOneConversationHero == this.QuestGiver)).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
        TextObject npcDiscussLine = new TextObject("{=!}{GANG_LEADER_NEEDS_RECRUITS_QUEST_NOTABLE_DISCUSS}");
        TextObject npcResponseLine = new TextObject("{=!}{GANG_LEADER_NEEDS_RECRUITS_QUEST_NOTABLE_RESPONSE}");
        bool changeDialogAfterTransfer = false;
        this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss").BeginNpcOptions().NpcOption(new TextObject("{=BGgDjRcW}I think that's enough. Here is your payment."), (ConversationSentence.OnConditionDelegate) (() => Hero.OneToOneConversationHero == this.QuestGiver && this._playerReachedRequestedAmount)).Consequence((ConversationSentence.OnConsequenceDelegate) (() =>
        {
          this.ApplyQuestSuccessConsequences();
          this.CompleteQuestWithSuccess();
        })).CloseDialog().NpcOption(npcDiscussLine, (ConversationSentence.OnConditionDelegate) (() =>
        {
          if (Hero.OneToOneConversationHero != this.QuestGiver)
            return false;
          if (!changeDialogAfterTransfer)
          {
            npcDiscussLine.SetTextVariable("GANG_LEADER_NEEDS_RECRUITS_QUEST_NOTABLE_DISCUSS", new TextObject("{=1hpeeCJD}Have you found any good men?[ib:confident3]"));
            changeDialogAfterTransfer = true;
          }
          else
          {
            npcDiscussLine.SetTextVariable("GANG_LEADER_NEEDS_RECRUITS_QUEST_NOTABLE_DISCUSS", new TextObject("{=ds294zxi}Anything else?"));
            changeDialogAfterTransfer = false;
          }
          return true;
        })).BeginPlayerOptions().PlayerOption(new TextObject("{=QbaOoilS}Yes, I have brought you a few men.")).Condition((ConversationSentence.OnConditionDelegate) (() => ((!this.CheckIfThereIsSuitableRecruitInPlayer() ? 0 : (!this._playerReachedRequestedAmount ? 1 : 0)) & (changeDialogAfterTransfer ? 1 : 0)) != 0)).NpcLine(npcResponseLine).Condition((ConversationSentence.OnConditionDelegate) (() =>
        {
          if (this._playerReachedRequestedAmount)
            return false;
          npcResponseLine.SetTextVariable("GANG_LEADER_NEEDS_RECRUITS_QUEST_NOTABLE_RESPONSE", new TextObject("{=70LnOZzo}Very good. Keep searching. We still need more men.[ib:hip2]"));
          return true;
        })).Consequence(new ConversationSentence.OnConsequenceDelegate(this.OpenRecruitDeliveryScreen)).PlayerLine(new TextObject("{=IULW8h03}Sure.")).Consequence((ConversationSentence.OnConsequenceDelegate) (() =>
        {
          if (!this._playerReachedRequestedAmount || !Campaign.Current.ConversationManager.IsConversationInProgress)
            return;
          Campaign.Current.ConversationManager.ContinueConversation();
        })).GotoDialogState("quest_discuss").PlayerOption(new TextObject("{=PZqGagXt}No, not yet. I'm still looking for them.")).Condition((ConversationSentence.OnConditionDelegate) (() => !this._playerReachedRequestedAmount & changeDialogAfterTransfer)).Consequence((ConversationSentence.OnConsequenceDelegate) (() => changeDialogAfterTransfer = false)).NpcLine(new TextObject("{=L1JyetPq}I am glad to hear that.[ib:closed2]")).CloseDialog().PlayerOption(new TextObject("{=OlOhuO7X}No thank you. Good day to you.")).Condition((ConversationSentence.OnConditionDelegate) (() => !this._playerReachedRequestedAmount && !changeDialogAfterTransfer)).CloseDialog().EndPlayerOptions().CloseDialog().EndNpcOptions();
      }

      private void OpenRecruitDeliveryScreen()
      {
        PartyScreenManager.OpenScreenWithCondition(new IsTroopTransferableDelegate(this.IsTroopTransferable), new PartyPresentationDoneButtonConditionDelegate(this.DoneButtonCondition), new PartyPresentationDoneButtonDelegate(this.DoneClicked), (PartyPresentationCancelButtonDelegate) null, PartyScreenLogic.TransferState.Transferable, PartyScreenLogic.TransferState.NotTransferable, this.QuestGiver.Name, this._requestedRecruitCount - this._deliveredRecruitCount, false, false, PartyScreenMode.TroopsManage);
      }

      private Tuple<bool, TextObject> DoneButtonCondition(
        TroopRoster leftMemberRoster,
        TroopRoster leftPrisonRoster,
        TroopRoster rightMemberRoster,
        TroopRoster rightPrisonRoster,
        int leftLimitNum,
        int rightLimitNum)
      {
        if (this._requestedRecruitCount - this._deliveredRecruitCount >= leftMemberRoster.TotalManCount)
          return new Tuple<bool, TextObject>(true, (TextObject) null);
        int variable = this._requestedRecruitCount - this._deliveredRecruitCount;
        TextObject textObject = new TextObject("{=VOr3uoRZ}You can only transfer {X} recruit{?IS_PLURAL}s{?}{\\?}.");
        textObject.SetTextVariable("IS_PLURAL", variable > 1 ? 1 : 0);
        textObject.SetTextVariable("X", variable);
        return new Tuple<bool, TextObject>(false, textObject);
      }

      private bool DoneClicked(
        TroopRoster leftMemberRoster,
        TroopRoster leftPrisonRoster,
        TroopRoster rightMemberRoster,
        TroopRoster rightPrisonRoster,
        FlattenedTroopRoster takenPrisonerRoster,
        FlattenedTroopRoster releasedPrisonerRoster,
        bool isForced,
        PartyBase leftParty,
        PartyBase rightParty)
      {
        foreach (TroopRosterElement troopRosterElement in (List<TroopRosterElement>) leftMemberRoster.GetTroopRoster())
        {
          this._rewardGold += this.RewardForEachRecruit(troopRosterElement.Character) * troopRosterElement.Number;
          this._deliveredRecruitCount += troopRosterElement.Number;
        }
        this._questProgressLogTest.UpdateCurrentProgress(this._deliveredRecruitCount);
        this._questProgressLogTest.TaskName.SetTextVariable("TOTAL_REWARD", this._rewardGold);
        if (this._deliveredRecruitCount == this._requestedRecruitCount)
        {
          this._playerReachedRequestedAmount = true;
          if (Campaign.Current.ConversationManager.IsConversationInProgress)
            Campaign.Current.ConversationManager.ContinueConversation();
        }
        return true;
      }

      private int RewardForEachRecruit(CharacterObject recruit)
      {
        return (int) (100.0 * (recruit.Tier <= 1 ? 1.0 : (recruit.Tier <= 3 ? 1.5 : 2.0)));
      }

      private bool IsTroopTransferable(
        CharacterObject character,
        PartyScreenLogic.TroopType type,
        PartyScreenLogic.PartyRosterSide side,
        PartyBase leftOwnerParty)
      {
        if (this._requestedRecruitCount - this._deliveredRecruitCount < 0)
          return false;
        if (side == PartyScreenLogic.PartyRosterSide.Left)
          return true;
        return MobileParty.MainParty.MemberRoster.Contains(character) && character.Occupation == Occupation.Bandit;
      }

      private bool CheckIfThereIsSuitableRecruitInPlayer()
      {
        bool flag = false;
        foreach (TroopRosterElement troopRosterElement in (List<TroopRosterElement>) MobileParty.MainParty.MemberRoster.GetTroopRoster())
        {
          if (troopRosterElement.Character.Occupation == Occupation.Bandit)
          {
            flag = true;
            break;
          }
        }
        return flag;
      }

      private void ApplyQuestSuccessConsequences()
      {
        this.AddLog(this.QuestSuccessLog);
        TraitLevelingHelper.OnIssueSolvedThroughQuest(this.QuestGiver, new Tuple<TraitObject, int>[1]
        {
          new Tuple<TraitObject, int>(DefaultTraits.Honor, 30)
        });
        GiveGoldAction.ApplyBetweenCharacters((Hero) null, Hero.MainHero, this._rewardGold);
        this.QuestGiver.AddPower(10f);
        this.RelationshipChangeWithQuestGiver = 5;
      }

      protected override void OnBeforeTimedOut(
        ref bool completeWithSuccess,
        ref bool doNotResolveTheQuest)
      {
        if (this._deliveredRecruitCount < this._requestedRecruitCount)
          return;
        completeWithSuccess = true;
        this.ApplyQuestSuccessConsequences();
      }

      protected override void OnTimedOut()
      {
        this.AddLog(this.QuestFailedWithTimeOutLogText);
        this.QuestGiver.AddPower(10f);
        this.RelationshipChangeWithQuestGiver = -5;
      }

      protected override void InitializeQuestOnGameLoad() => this.SetDialogs();

      protected override void HourlyTick()
      {
      }
    }

    public class GangLeaderNeedsRecruitsIssueBehaviorTypeDefiner : SaveableTypeDefiner
    {
      public GangLeaderNeedsRecruitsIssueBehaviorTypeDefiner()
        : base(820000)
      {
      }

      protected override void DefineClassTypes()
      {
        this.AddClassDefinition(typeof (GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssue), 1);
        this.AddClassDefinition(typeof (GangLeaderNeedsRecruitsIssueBehavior.GangLeaderNeedsRecruitsIssueQuest), 2);
      }
    }
  }
}
